package com.cindata

class AccountInspect
{
    Integer year
    Date startTime
    Date endTime
    String status
    String result
    String memo
    Workflow workflow

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user // 年检人员
    User createBy
    User modifyBy

    static belongsTo = [account: Account]

    static mapping = {
        autowire true
    }
    static constraints = 
    {
    	year nullable: true, blank: true
    	startTime nullable: true, blank: true
    	startTime nullable: true, blank: true
        status maxSize: 20, nullable: true, blank: true
		status inList: ["Pending", "Failed", "Completed"]
		result maxSize: 20, nullable: true, blank: true
        result inList: ['通过', '不通过']
		memo maxSize: 200, nullable: true, blank: true

		workflow nullable: true, blank: true

		createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        user nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
    }

    def springSecurityService
    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        def createBy = User.findByUsername(username)
        if (!user) 
        {
        	user = createBy
        }
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}